########################################
# Author: Healer
# Email: healer_kx@163.com
# 
# 
# 

require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')



def gsub_content content, name, group
    content.gsub!(/\{%\$name%\}/, name)
    content.gsub!(/\{%\$name-low%\}/, name.downcase)
    content.gsub!(/\{%\$group%\}/, group) if group
    content
end

# ruby widget.rb new <name>
def new_widget name, group
    # Write JavaScript file

    content = ruby_template './Rbts/widget.rbt'
    content = gsub_content(content, name, group)
    path = project_widget_path group, Everest::TypeWidget
    result = create_file path, "#{name}.js", content

    # Write HTML file
    content = ruby_template './Rbts/widget.tpl.rbt'
    content = gsub_content(content, name, group)
    path = project_widget_path group, Everest::TypeHTML
    result = create_file path, "#{name.downcase}.html", content

    # Write CSS file
    content = ruby_template './Rbts/widget.css.rbt'
    content = gsub_content(content, name, group)
    path = project_widget_path group, Everest::TypeCSS
    result = create_file path, "#{name.downcase}.css", content    


    # Write Test Case PHP File
    content = ruby_template './Rbts/widget.case.php.rbt'
    content = gsub_content(content, name, group)
    path = project_widget_path group, Everest::TypeCasePHP
    result = create_file path, "#{name.downcase}.case.php", content    


    # Write Test Case HTML File
    content = ruby_template './Rbts/widget.case.page.rbt'
    content = gsub_content(content, name, group)
    path = project_widget_path group, Everest::TypeCasePage
    result = create_file path, "#{name.downcase}case.html", content    

end

#ruby widget.rb list
def list_widget()
  # List all APIs.
end


# ruby widget.rb del <name>
def del_widget name

  puts "Delete Widget #{name}.\n"
end


#mode, name = *ARGV

if $mode_name === Everest::ModeNew
    puts "Create Widget '#{$module_name}' and its template html."
    group = $args[0]
    new_widget($module_name, group)
elsif $mode_name === Everest::ModeDelete
    puts "Delete Widget '#{$module_name}'."
    del_widget($module_name)
end

#p project_path('api', 'cc.php')



